package com.RPGDice;

import com.RPGDice.History;
import com.criticalritrpg.*;
import com.RPGDice.RollActivity;
import com.RPGDice.SettingsActivity;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;

public class RollMain extends Activity implements OnClickListener {

	Button rollDices, settings, help, exit, history;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main_dados);

		rollDices = (Button) findViewById(R.id.roll_button);
		rollDices.setOnClickListener(this);

		settings = (Button) findViewById(R.id.settings_button);
		settings.setOnClickListener(this);

		help = (Button) findViewById(R.id.help_button);
		help.setOnClickListener(this);

		exit = (Button) findViewById(R.id.exit_button);
		exit.setOnClickListener(this);
		
		history = (Button) findViewById(R.id.history_button);
		history.setOnClickListener(this);

	}

	public void onClick(View v) {
		Intent mIntent;
		switch (v.getId()) {
		case R.id.roll_button:
			mIntent = new Intent(getApplicationContext(),
					RollActivity.class);
			startActivity(mIntent);
			break;
		case R.id.settings_button:
			mIntent = new Intent(getApplicationContext(),
					SettingsActivity.class);
			startActivity(mIntent);
			break;
		case R.id.history_button:
			mIntent = new Intent(getApplicationContext(),
					History.class);
			startActivity(mIntent);
			break;
		case R.id.help_button:
			showHelpDialog();
			break;
		case R.id.exit_button:
			askForExit();
			break;
		}

	}
	
	private void showHelpDialog(){
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setMessage(R.string.help_text_roll)
		       .setCancelable(true);
		AlertDialog alert = builder.create();
		alert.show();
	}

	private void askForExit() {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setMessage(R.string.exit_message)
				.setCancelable(false)
				.setPositiveButton(R.string.yes,
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								RollMain.this.finish();
							}
						})
				.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						dialog.cancel();
					}
				});
		AlertDialog alert = builder.create();
		alert.show();
	}
}